//
//  XSQMainViewController.swift
//  WeiBo
//
//  Created by 许世强 on 2017/3/26.
//  Copyright © 2017年 许世强. All rights reserved.
//

//根视图控制器
import UIKit

class XSQMainViewController: UITabBarController,XSQTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置为代理
        XSQTabBar().xsqDelegate = self
        
        //将系统的tabBar替换成自定义的tabBar  使用kvc进行赋值,动态向对象发送消息
        self.setValue(XSQTabBar(), forKey: "tabBar")
        
        addChildViewController(childController: XSQHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        
        addChildViewController(childController: XSQMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(childController: XSQDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        
        addChildViewController(childController: XSQMineTableViewController(), imageName: "tabbar_profile", title: "我的")
    }

    //重载添加子视图控制器的方法
    func addChildViewController(childController: UIViewController, imageName:String, title:String) {
        
        //设置tabBarItem图片
        childController.tabBarItem.image = UIImage(named:imageName)
        
        //设置tabBarItem选中的图片  设置渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
        
        //设置标题
        childController.title = title;
        
        //创建导航控制器视图
        let nav = XSQNavigationController(rootViewController:childController)
        
        //tabBarVC添加子视图控制器
        addChildViewController(nav)
    }
    
    //自定义tabBar的代理方法的实现
    func didSeletedComposeButton() {
        
        print("实现了代理方法")
    
    }

}
